import time

from Logger import logger_gen
logger = logger_gen.get_logger(__name__)


# 日志装饰器
def log_execution(logger=logger, grade='info'):
    def decorator(func):
        def wrapper(*args, **kwargs):
            logger_grade = {
                'error': logger.error,
                'warn': logger.warn,
                'info': logger.info,
                'debug': logger.debug
            }
            logger_grade[grade](f"函数 {func.__name__} 参数 args: {args}, kwargs: {kwargs}")
            result = func(*args, **kwargs)
            logger_grade[grade](f"{func.__name__} 返回: {result}")
            return result
        return wrapper
    return decorator


def timer(func):
    def wrapper(*args, **kwargs):
        start_time = time.perf_counter()
        result = func(*args, **kwargs)
        end_time = time.perf_counter()
        print(f"{func.__name__} 函数执行花费了 {end_time - start_time} 秒")
        return result
    return wrapper


if __name__ == '__main__':
    # @validate_input(1, 10)
    # def process_value(value):
    #     print(f"Processing value: {value}")
    #
    # process_value(11)

    @log_execution(logger)
    def test_log_execution(value):
        print(f"Processing value: {value}")
